#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

const int maxn = 1e5 + 20;
int n, m;
int a[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        a[i] = i + 1;
    }
    a[n] = 1;
    int p = n;
    for (int j = 0; j < n-1; j++) {
        for (int i = 1; i <= m-1; i++) {
            p = a[p];
        }
        int q = a[p], r = a[q];
        a[p] = r;
        a[q] = -1;
        for (int i = 1; i <= n; i++) {
            if (a[i] != -1)cout << i << " ";
        }
        cout<<endl;

    }


    return 0;
}
